﻿using System;
using System.Collections.Generic;
using System.Text;
using AppToolKit.Core.Context.Spring;
using System.Data;

namespace BLL.Business
{
    [AutoWiring]
    public class AllotMentBuesiness
    {
        private const string ID = "code";
        [AutoWiring]
        public AllotMentBuesinessDao Dao { get; set; }

        public DataSet GetTaskAllot(string taskListID)
        {
          return   Dao.GetTaskAllot(taskListID);
        }
        public DataSet GetTask(string tasklistID)
        {
            return Dao.GetTask(tasklistID);
        }
        public void AddTaskAllot(string listID, string taskID)
        {
            Dao.AddTaskAllot(listID, taskID);
        }
        public void DelTaskAllot(string listID, string taskID)
        {
            Dao.DelTaskAllot(listID, taskID);

        }

        public void SaveAlloment(string hotelid, List<string> tasklist_code)
        {
            DelAllTaskListAlloment(hotelid, tasklist_code);
             foreach (string key in tasklist_code)
             {
                 if (!Exist(hotelid, key))
                 {                  
                     Insert(hotelid,key);
                 }
             }
        }

        private void Insert(string hotelid, string key)
        {
            Dao.Insert(hotelid, key);
        }

        

        private bool Exist(string hotelid, string key)
        {
           return  Dao.Exist(hotelid, key);
        }
        private void DelAllTaskListAlloment(string hotelid,List<string> tasklist_code)
        {
            DataSet ds= Dao.GetAllTaskListAlloment(hotelid);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (!tasklist_code.Contains(Convert.ToString(dr[ID]).Trim()))
                {
                    Dao.DelTaskListAllot(hotelid,Convert.ToString(dr[ID]).Trim());
                }
            }

            
        }
    }
}
